********************************************************************
******** "Does Political Diversity Inhibit Blood Donations?" *******
********************************************************************

use "KimPelc_Blood_PoP.dta", clear

***********************************************
******** Tables 1-2 and Figures 1-2, 4 ********
***********************************************

* Table 1: Social Diversity and Blood Donation

eststo clear

eststo: reg donate_blood dist_st_ideo5_3 st_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state , cluster(state) 
eststo: reg donate_blood dist_st_ideo5_3 ideo5_3 st_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state , cluster(state) 

eststo: reg donate_blood dist_st_ideo5_3 st_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year, cluster(state) 
eststo: reg donate_blood dist_st_ideo5_3 ideo5_3 st_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year, cluster(state) 

eststo: reg donate_blood dist_cz_ideo5_3 cz_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state , cluster(czone) 
eststo: reg donate_blood dist_cz_ideo5_3 ideo5_3 cz_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state , cluster(czone) 

eststo: reg donate_blood dist_cz_ideo5_3 cz_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year, cluster(czone) 
eststo: reg donate_blood dist_cz_ideo5_3 ideo5_3 cz_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year, cluster(czone) 

esttab using "Table1.tex", label keep(dist_st_ideo5_3 st_mean_ideo5_3 dist_cz_ideo5_3 cz_mean_ideo5_3 ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate) order(dist_st_ideo5_3 st_mean_ideo5_3 dist_cz_ideo5_3 cz_mean_ideo5_3 ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvars indicate("State FE = *state*" "Year FE = *year*") 


* Table 2: Social Diversity and Blood Donation, by Age

eststo clear

* Age < 40
eststo: reg donate_blood dist_st_ideo5_3 st_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year if age < 40, cluster(state) 
eststo: reg donate_blood dist_st_ideo5_3 ideo5_3 st_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year if age < 40, cluster(state) 

eststo: reg donate_blood dist_cz_ideo5_3 cz_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year if age < 40, cluster(czone) 
eststo: reg donate_blood dist_cz_ideo5_3 ideo5_3 cz_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year if age < 40, cluster(czone) 
 
* Age >= 40
eststo: reg donate_blood dist_st_ideo5_3 st_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year if age >= 40, cluster(state) 
eststo: reg donate_blood dist_st_ideo5_3 ideo5_3 st_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year if age >= 40, cluster(state) 

eststo: reg donate_blood dist_cz_ideo5_3 cz_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year if age >= 40, cluster(czone) 
eststo: reg donate_blood dist_cz_ideo5_3 ideo5_3 cz_mean_ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k white black race_hispanic asian nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate i.state i.year if age >= 40, cluster(czone) 
 
esttab using "Table2.tex", label keep(dist_st_ideo5_3 st_mean_ideo5_3 dist_cz_ideo5_3 cz_mean_ideo5_3 ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate ) order(dist_st_ideo5_3 st_mean_ideo5_3 dist_cz_ideo5_3 cz_mean_ideo5_3 ideo5_3 fb_share age female college hs citizen_dum income_100k income_50k nohealthinsurance_dum log_blood L1_firearm_death_rate incarcerated_rate ) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvars indicate("State FE = *state*" "Year FE = *year*") 

* Figure 1: Variation in Regional Ideological Polarization Over Time

bysort state year: egen avg_dist_st_ideo5_3 = mean(dist_st_ideo5_3)
bysort state year: gen n = _n

graph box avg_dist_st_ideo5_3 if year > 2007 & year < 2020 & n == 1, ///
 box(1, color(maroon)) over(year) marker(1, msymbol(circle_hollow) msize(vsmall) mcolor(maroon)) graphregion(color(white) margin(small)) ytitle("Average Ideological Distance, within State")

graph save "Figure1.gph", replace
graph export "Figure1.pdf", replace

* Figure 4: Probability of Blood Donation, by Ideological Viewpoint

xi: probit donate_blood i.ideo5_3 
margins, over(ideo5_3)
marginsplot, x(ideo5_3) plot1opts(mcolor(maroon) mlcolor(maroon) lpattern(dot) lwidth(none)) ci1opts(lcolor(maroon)) ///
	addplot(hist ideo5_3, xlab(, valuelabel) xtitle("") barwidth(0.5) fcolor(none) lcolor(gs5) yaxis(2) ylabel(0(2)6, axis(2)) yscale(alt axis(2)) ytitle("Ideology (Density)", axis(2))) ytitle("Pr (Donate blood)", color(maroon)) level(95) legend(off) ///
	title("") plotregion(fcolor(white)) graphregion(fcolor(white))
	
graph save "Figure4.gph", replace
graph export "Figure4.pdf", replace

* Figure 2: Trend in Blood Donation Over Time

svyset [pweight = weight]
svy: mean donate_blood, over(year)

matrix mean = e(b)'
svmat mean

matrix V = e(V)   
matrix Var = vecdiag(V)'
svmat Var

keep mean* Var*

gen year = (1004+_n)*2

replace mean1 = round(mean1*100,.1)

keep if _n < 7

gen mean_u = mean1+sqrt(Var1)*1.96*100
gen mean_l = mean1-sqrt(Var1)*1.96*100

graph twoway (bar mean1 year, color(gs6)) (rcap mean_u mean_l year) ///
 (scatter mean1 year, msymbol(none) mlabel(mean1) mlabposition(6) mlabgap(0.2cm) mlabsize(medsmall) mlabcolor(black)), ///
 legend(off) ylabel(0(5)20) graphregion(color(white) margin(small)) xtitle("Year") ytitle("Blood donation (%)")

graph save "Figure2.gph", replace 
graph export "Figure2.pdf", replace 


use "KimPelc_Blood_Respondi_PoP.dta", clear

********************************************
******** Tables 3-4 and Figures 5-6 ********
********************************************

* Table 3: Subjective Social Diversity and Blood Donation

eststo clear

eststo: reg blood political_minority , cluster(state)
eststo: reg blood race_minority , cluster(state)
eststo: reg blood political_minority race_minority , cluster(state)
eststo: reg blood political_minority race_minority ideology college hs female age citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate, cluster(state)
eststo: reg blood political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate, cluster(state)
eststo: xi: reg blood political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate i.state , cluster(state) 

esttab using "Table3.tex", label keep(political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate) order(political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvar // addnotes("Standard errors in parentheses." 

* Table 4: Subjective Social Diversity and Blood Donation, by Age

eststo clear
eststo: reg blood political_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate if age < 40, cluster(state)
eststo: reg blood race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate if age < 40, cluster(state)
eststo: reg blood political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate if age < 40, cluster(state)
eststo: xi: reg blood political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate i.state  if age < 40, cluster(state) 

eststo: reg blood political_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate if age >= 40, cluster(state)
eststo: reg blood race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate if age >= 40, cluster(state)
eststo: reg blood political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate if age >= 40, cluster(state)
eststo: xi: reg blood political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate i.state  if age >= 40, cluster(state) 

esttab using "Table4.tex", label keep(political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate) order(political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center firearm_death_rate incarcerated_rate) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvar // addnotes("Standard errors in parentheses." 

* Figure 5: Respondents’ beliefs about how common their political / racial identity are in their area (0 = “highly common”, 10 = “highly uncommon”)

histogram political_minority, fcolor(gs13) lcolor(black) barwidth(0.5) ylabel(0(0.2)0.8) xlabel(0(1)10) ///
	xtitle("") title("Self-Perception as Political Minority in Region", size(medsmall) color(black)) ///
	plotregion(fcolor(white)) graphregion(fcolor(white)) ysize(3) xsize(3) plotregion(lcolor(black))
	
graph save "Figure5a.gph", replace
graph export "Figure5a.pdf", replace

histogram race_minority, fcolor(gs13) lcolor(black) barwidth(0.5) ylabel(0(0.2)0.8) xlabel(0(1)10) ///
	xtitle("") title("Self-Perception as Political Minority in Region", size(medsmall) color(black)) ///
	plotregion(fcolor(white)) graphregion(fcolor(white)) ysize(3) xsize(3) plotregion(lcolor(black))

graph save "Figure5b.gph", replace
graph export "Figure5b.pdf", replace

* Figure 6: Coefficient Plots for the Effects of Subjective Social Diversity and Ideology

areg blood political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center, cluster(state) abs(state)
estimates store all

areg blood political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center if age < 40, cluster(state) abs(state)
estimates store young

areg blood political_minority race_minority ideology college hs female age income_100k income_50k citizen_us white black asian hispanic log_center if age >= 40, cluster(state) abs(state)
estimates store old

*ssc install grstyle /* in order to use the code below, grstyle should be instaled */

grstyle init
grstyle color background white // set overall background to white

coefplot all, bylabel("Overall") ///
  || young old, bylabel("By Age Group") ///
  || , keep(political_minority race_minority ideology) norecycle  byopts(legend(position(5))) xline(0) legend(cols(3) label(2 "All") label(4 "Age < 40") label(6 "Age ≥ 40") region(lwidth(none))) subtitle(,bcolor(white))
  
graph save "Figure6.gph", replace
graph export "Figure6.pdf", as(pdf) name("Graph") replace




